package com.dht.xiao.jianye.dialog;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.dht.xiao.jianye.R;


/**
 * Created by Administrator on 2017-08-17.
 */

public class YesNoDialog {
    //@BindView(R.id.bt_cancle)

    Button btSure;
    TextView txHint;
    private Context context;
    private OnCallBack onCallBack;
    private String hint;
    public YesNoDialog(Context context,String hint) {
        this.context = context;
        this.hint = hint;
        DialogInit();
    }

    private void DialogInit() {

        final AlertDialog.Builder Builder =
                new AlertDialog.Builder(context, R.style.DialogHint);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_yesno, null);
       // ButterKnife.bind(this, view);

        btSure = (Button)view.findViewById(R.id.bt_sure);
        txHint = (TextView) view.findViewById(R.id.hint);
        txHint.setText(hint);
        Builder.setView(view);
        Builder.setCancelable(false);
        final AlertDialog dialog = Builder.show();
        WindowManager.LayoutParams params =
                dialog.getWindow().getAttributes();
        WindowManager manager = ((Activity) context).getWindowManager();
        Display d = manager.getDefaultDisplay(); // 获取屏幕宽、高度
        params.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialog.getWindow().setAttributes(params);

        btSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCallBack != null) {
                    onCallBack.sure();
                    dialog.dismiss();
                }
            }
        });


    }


    public void setOnCallBackListener(OnCallBack onCallBack) {
        this.onCallBack = onCallBack;
    }


    public interface OnCallBack {
        public void sure();

    }
}
